project(embedTest)
message(STATUS "[${PROJECT_NAME}]")

set(embed_src ${CMAKE_CURRENT_SOURCE_DIR}/embedSrc)
message(STATUS "DEBUG embed_src = ${embed_src}")
set(command_build ${CMAKE_CURRENT_BINARY_DIR}/embedSrc)
message(STATUS "DEBUG command build = ${command_build}")
set(work_dir ${embed_src})
message(STATUS "DEBUG work dir = ${embed_src}")
set(embeddable_dir ${CMAKE_CURRENT_BINARY_DIR}/embeddable)
message(STATUS "DEBUG embeddable_dir = ${embeddable_dir}")

file(MAKE_DIRECTORY ${command_build})

set(custom_target_name ${PROJECT_NAME}_make_embeddable)
message(STATUS "custom_target_name = ${custom_target_name}")

file(GLOB embed_files "${embed_src}/*.txt")
foreach(embed_file ${embed_files})
    list(APPEND embed_file_list, embed_file)
    get_fileName_component(fileName ${embed_file} NAME_WE)
    get_fileName_component(fileExt ${embed_file} EXT)
    set(embeddable_file "${CMAKE_CURRENT_BINARY_DIR}/../embeddable/${fileName}${fileExt}")
    list(APPEND embeddable_file_list, embeddable_file)
endforeach()

add_custom_target(
    ${custom_target_name}
    COMMAND ${CMAKE_COMMAND} -S ${embed_src} -B ${command_build}
    WORKING_DIRECTORY ${work_dir}
    COMMENT "make embeddable of embedTest"
    DEPENDS ${embed_file_list}
    BYPRODUCTS ${embeddable_file_list}
)

include_directories(${embeddable_dir})

add_executable(${PROJECT_NAME} main.cpp ${embeddable_file_list})
add_dependencies(${PROJECT_NAME} ${custom_target_name})

